<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>免费报价</title>
    <!--css style-->
    <link rel="stylesheet" href="css/base.css">
    <link rel="stylesheet" href="css/style.css">
    <link rel="stylesheet" href="css/font.css">
    <link rel="stylesheet" href="responsive/flexible.css">
    <script src="responsive/flexible.js"></script>
</head>
<body class="personal_center quote inner_page">
    <header>
        <a href="javascript:void(0)" class="pre_page"></a>
        <a href="index.html" class="home"></a>
        免费报价
    </header>

    <section class="main">
       <div class="container">
           <h2>我家装修得多少钱?</h2>
           <p>今天已有 1758 位业主获取了装修预算</p>
           <form action="quote_res.html" class="quote_form container">

                <div class="error_message"></div>
               <ul>
                   <li>
                       <select name="province" id="s_province">
                           <option disabled value="选择你所在的城市" selected="selected">选择你所在的城市</option>
                       </select>
                   </li>
                   <li>
                        <input type="text" placeholder="请输入您的房屋面积" name="room" id="room" onblur="checkRoom(this)">
                        <i>m<sup>2</sup></i>

                   </li>
                   <li class="space1">
                       <div class="input_wrapper">
                           <input type="number" placeholder="1-5" name="rooms" id="rooms" class="rooms" min="1" max="5" onblur="checkEmpty(this,'此处不能留空')">
                           <i>室</i>
                       </div>
                       <div class="input_wrapper">
                           <input type="number" placeholder="1-5" name="halls" id="halls" class="halls" min="1" max="5" onblur="checkEmpty(this,'此处不能留空')">
                           <i>厅</i>
                       </div>


                   </li>
                   <li class="space2">
                       <div class="input_wrapper">
                           <input type="number" placeholder="1-5" name="kitchens" id="kitchen" class="kitchen" min="1" max="5" onblur="checkEmpty(this,'此处不能留空')">
                           <i>厨</i>
                       </div>
                       <div class="input_wrapper">
                           <input type="number" placeholder="1-3" name="restroom" id="restroom" class="restroom" min="1" max="3" onblur="checkEmpty(this,'此处不能留空')">
                           <i>卫</i>

                       </div>
                       <div class="input_wrapper">
                           <input type="number" placeholder="1-5" name="balcony" id="balcony" class="balcony" min="1" max="5" onblur="checkEmpty(this,'此处不能留空')">
                           <i>阳台</i>
                       </div>



                   </li>
                   <li>

                       <input type="text" placeholder="输入手机号码，报价结果将发送到您的手机" name="telephone" id="telephone" onblur="checkTel(this)">
                   </li>

                   <div class="clear"></div>
               </ul>

               <input type="submit" value="立即计算" onclick="checkEvaluateInfo()">
           </form>

       </div>

    </section>


</body>
<script src="js/jquery.js"></script>
<script src="js/area.js"></script>
<script type="text/javascript">_init_area(["s_province"]);</script>
<script>
    /*检测房屋面积*/
    function checkRoom(obj) {
        obj.errorFlag = false;
        if (checkEmpty(obj, '请您填写房屋面积')) {
            obj.errorFlag = true;
            return obj.errorFlag;
        }
        if (!(/[0-9]/.test(obj.value))) {
            showErrorMessage("输入房屋面积格式不正确");
            obj.errorFlag = true;
        }else{
            clearErrorMessage();
        }
    }
    /*校验手机号码*/
    function checkTel(obj){
        obj.errorFlag = false;
        if (checkEmpty(obj,'请您填写手机号码')) {
            obj.errorFlag = true;
            return  obj.errorFlag;
        }
        if(!(/^1[3|4|5|7|8]\d{9}$/.test(obj.value))){
            showErrorMessage("输入手机号码不正确");
            obj.errorFlag = true;
        }else {
            clearErrorMessage();
        }
        return  obj.errorFlag;
    }
    /*检测是否为空*/
    function checkEmpty(obj,message){
        if(obj.value==''){
            showErrorMessage(message);
            return true;
        }else{
            clearErrorMessage();
            return false;
        }
    }
    /*检测计算数据*/
    function checkEvaluateInfo(){
        var elTel=document.getElementById("telephone");
        var elRoom=document.getElementById("room");
        var elRooms=document.getElementById("rooms");
        var elHalls=document.getElementById("halls");
        var elKitchen=document.getElementById("kitchen");
        var elRestroom=document.getElementById("restroom");
        var elBalcony=document.getElementById("balcony");

        /*检测地区*/
        if($("#s_province option:checked").eq(0).index()==0){
            showErrorMessage("请选择所在地区");
            $(".quote_form").submit(false);
            return;

        }
        if(checkRoom(elRoom)){
            $(".quote_form").submit(false);
            return;
        }
        if(checkEmpty(elRooms,"室不能为空")){
            $(".quote_form").submit(false);
            return;
        }
        if(checkEmpty(elHalls,"厅不能为空")){
            $(".quote_form").submit(false);
            return;
        }

        if(checkEmpty(elKitchen,"厨不能为空")){
            $(".quote_form").submit(false);
            return;
        }
        if(checkEmpty(elRestroom,"卫不能为空")){
            $(".quote_form").submit(false);
            return;
        }
        if(checkEmpty(elBalcony,"阳台不能为空")){
            $(".quote_form").submit(false);
            return;
        }

        if(checkTel(elTel)){
            $(".quote_form").submit(false);
            return;
        }

    }
    function showErrorMessage(message){
        $(".error_message").html("*"+message);
    }

    function clearErrorMessage() {
        $(".error_message").html("");
    }


</script>
</html>